package com.yunhe.tianhe.rentcars.controller.client;/**
 * Created by Administrator on 2017/11/25 0025.
 */

import com.yunhe.tianhe.commons.dto.Pageable;
import com.yunhe.tianhe.rentcars.dto.JSONResponse;
import com.yunhe.tianhe.rentcars.entity.client.BlackClient;
import com.yunhe.tianhe.rentcars.service.client.BlackClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @user yanxiu
 * @creat 2017-11-25 下午 5:33
 * @desc
 **/
@Controller
@RequestMapping("/black")
public class BlackClientController {
    @Autowired
    private BlackClientService blackClientService;

    @RequestMapping
    public String list() {
        return "client/black/blackClient";
    }


    @RequestMapping("/listData")
    @ResponseBody
    public Pageable<BlackClient> findPage(Integer offset, Integer limit, String name, String mobile, String idCard){
        Pageable<BlackClient> page = blackClientService.findPage(offset, limit, name, mobile, idCard);
        return page;
    }

    @RequestMapping("/add")
    public String add(){
        return "client/black/add";
    }

    @RequestMapping("/saveAjax")
    @ResponseBody
    public JSONResponse save(BlackClient blackClient){
        blackClientService.save(blackClient);
        return JSONResponse.success("添加成功");
    }

    @RequestMapping("/deleteAjax")
    @ResponseBody
    public JSONResponse delete(String ids) {
        blackClientService.deleteBatch(ids);
        return JSONResponse.success("删除成功");
    }


    @RequestMapping("/edit")
    public String edit(HttpServletRequest req, Long id){
        BlackClient blackClient = blackClientService.findOne(id);
        req.setAttribute("blackClient",blackClient);
        return "client/black/edit";
    }

    @RequestMapping("/updateAjax")
    @ResponseBody
    public JSONResponse update(BlackClient blackClient){
        blackClientService.update(blackClient);
        return JSONResponse.success("修改成功！");
    }

}
